package org.afun.oldhand.user.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.afun.oldhand.R;
import org.afun.oldhand.base.BaseFragment;
import org.afun.oldhand.user.activity.BasicMsgActivity;
import org.afun.oldhand.user.activity.user_item1_2;
import org.afun.oldhand.user.activity.user_item1_4;
import org.afun.oldhand.user.adapter.UserItemAdapter;
import org.afun.oldhand.user.javabean.ItemBean;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link UserFrament#newInstance} factory method to
 * create an instance of this fragment.
 */
public class UserFrament  extends BaseFragment implements View.OnClickListener{

    private View view;
    private ListView listView;
    private List<ItemBean> data = new ArrayList<>();

    public UserFrament() {
        // Required empty public constructor
    }

    @Override
    public View initView() {
        // Inflate the layout for this fragment
        if(view == null){
            view = View.inflate(mContext, R.layout.fragment_user, null);
        }
        listView = view.findViewById(R.id.lv);
        data.add(new ItemBean("个人主页"));
        data.add(new ItemBean("优惠券"));
        data.add(new ItemBean("安全中心"));
        data.add(new ItemBean("客服中心"));
        data.add(new ItemBean("设置"));


        listView.setAdapter(new UserItemAdapter(data,this.mContext));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Log.e("test", "onItemClick: " + position);
                Intent intent;
                switch (position){
                    case 0:
                        Toast.makeText(mContext,"个人主页！",Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        intent=new Intent(mContext, user_item1_2.class);
                        mContext.startActivity(intent);
                        break;
                    case 2:
                        Toast.makeText(mContext,"安全中心！",Toast.LENGTH_SHORT).show();
                        break;
                    case 3:
                        intent=new Intent(mContext, user_item1_4.class);
                        mContext.startActivity(intent);
                        break;
                    case 4:
                        Toast.makeText(mContext,"设置！",Toast.LENGTH_SHORT).show();
                        break;
                    default:
                        break;
                }
            }
        });


        // 设置点击基本信息后进入基本信息界面
        TextView basic_msg = view.findViewById(R.id.textView3);
        basic_msg.setOnClickListener(this);

        return view;
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment UserFrament.
     */
    // TODO: Rename and change types and number of parameters
    public static UserFrament newInstance(String param1, String param2) {
        UserFrament fragment = new UserFrament();

        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.textView3:
                Intent intent=new Intent(mContext, BasicMsgActivity.class);
                mContext.startActivity(intent);
                break;
            default:
                break;
        }
    }
}